//package com.xyw.his00.utils.FileUtils;
//
//import com.itextpdf.text.*;
//import com.itextpdf.text.pdf.*;
//import com.xyw.his00.dto.InvoiceDTO;
//import com.xyw.his00.pojo.dbpojo.MedicalTechnology;
//import com.xyw.his00.pojo.dbpojo.PayOrder;
//import com.xyw.his00.pojo.newpojo.ExportPdfFileTemplate;
//import com.xyw.his00.utils.TimeUtils.DateUtil;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import org.springframework.stereotype.Component;
//
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//
//public class FileRequestUtil {
//    public static void ExportPdf(HttpServletRequest request,
//                                 HttpServletResponse response,
//                             PayOrder order
//                                ) throws Exception {
//        LocalDateTime currentTime = LocalDateTime.now();
//
//// 定义一个日期时间格式化器，用于将LocalDateTime对象转换为字符串
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//
//// 使用格式化器将当前时间转换为字符串
//        String currentDateTimeString = currentTime.format(formatter);
//        //告诉浏览器用什么软件可以打开此文件
//        //content-Type: application/pdf?还有什么类型
//        response.setHeader("content-Type", "application/pdf");
//        //下载文件的默认名称
//        // response.setHeader("Content-Disposition", "attachment;filename=XXX.pdf");
//        //设置中文
//        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
//        Font FontChinese = new Font(bfChinese, 12, Font.NORMAL);//设置中文字体,字号12，正常格式
//        //创建一个文档
//        Document document = new Document(PageSize.A4);
//        //创建第一个段落
//        Paragraph titleParagraph = new Paragraph();
//        //支持中文
//        titleParagraph.setFont(new Font(bfChinese, 20, Font.NORMAL));
//        //设置居中显示
//        titleParagraph.setAlignment(Element.ALIGN_CENTER);
//        titleParagraph.add("医院门诊病情消费记录单");
//        //创建第二个段落
//        Paragraph tipsParagraph = new Paragraph();
//        tipsParagraph.setFont(new Font(bfChinese, 10, Font.NORMAL));
//        tipsParagraph.setAlignment(Element.ALIGN_CENTER);
//        tipsParagraph.setLeading(tipsParagraph.getTotalLeading() + 10);
//        tipsParagraph.add("打印时间：" + DateUtil.getTodayYmd());
//
//        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
//
//        // 打开文档
//        document.open();
//        //设置文档标题
//        document.addTitle("收费记录单");
//        //设置文档作者
//        document.addAuthor("爱国敬业诚心为民微医院");
//        document.addCreationDate();
//        //设置关键字
//        document.addKeywords("iText");
//        document.addLanguage("中文");
//        //增加段落进入文档
//        document.add(titleParagraph);
//        document.add(tipsParagraph);
//        //表格
//        PdfPTable tableMessage = new PdfPTable(4);
//        tableMessage.setSpacingBefore(8f);
//        tableMessage.setSpacingAfter(8f);
//        //设置表格无边框
//        tableMessage.getDefaultCell().setBorder(0);
//        //设置表格宽度
//        tableMessage.setTotalWidth(new float[]{30, 120, 30, 120});
//        tableMessage.addCell(new Paragraph("患者姓名及编号", FontChinese));
//        tableMessage.addCell(new Paragraph(order.getPatientName()+order.getRegisterId(), FontChinese));
//        tableMessage.addCell(new Paragraph("目的", FontChinese));
//        tableMessage.addCell(new Paragraph( order.get FontChinese));
//        tableMessage.addCell(new Paragraph("位置", FontChinese));
//        tableMessage.addCell(new Paragraph(exportPdfFile.getPosition(),FontChinese));
//        tableMessage.addCell(new Paragraph("项目创建时间", FontChinese));
//        tableMessage.addCell(new Paragraph(exportPdfFile.getCreationTime().format(formatter),FontChinese));
//        tableMessage.addCell(new Paragraph("项目执行医生编号及名称", FontChinese));
//        tableMessage.addCell(new Paragraph(String.valueOf(exportPdfFile.getInputEmployeeId())+inputEmployeeName,FontChinese));
//        tableMessage.addCell(new Paragraph("输入检查医生编号及名称", FontChinese));
//        tableMessage.addCell(new Paragraph(String.valueOf(exportPdfFile.getResultEmployeeId())+resultEmployeeName,FontChinese));
//        tableMessage.addCell(new Paragraph("项目执行时间", FontChinese));
//        tableMessage.addCell(new Paragraph(exportPdfFile.getTime().format(formatter),FontChinese));
//        tableMessage.addCell(new Paragraph("项目执行结果", FontChinese));
//        tableMessage.addCell(new Paragraph(exportPdfFile.getResult(),FontChinese));
//        tableMessage.addCell(new Paragraph("状态", FontChinese));
//        tableMessage.addCell(new Paragraph(exportPdfFile.getState(),FontChinese));
//        tableMessage.addCell(new Paragraph("备注", FontChinese));
//        tableMessage.addCell(new Paragraph(exportPdfFile.getRemark(),FontChinese));
//        tableMessage.addCell(new Paragraph("出立费用单时间", FontChinese));
//        tableMessage.addCell(new Paragraph(currentDateTimeString, FontChinese));
//        document.add(tableMessage);
//
//
//        //病情表格
//        PdfPTable tableOrder = new PdfPTable(1);
//        //设置表格无边框
//        tableOrder.getDefaultCell().setBorder(0);
//        tableOrder.setSpacingBefore(30f);
//        tableOrder.setSpacingAfter(10f);
//
//        PdfPCell cell1 = new PdfPCell(new Paragraph("项目编码及名称 ", new Font(bfChinese, 14, Font.NORMAL)));
//        cell1.setFixedHeight(25);
//        cell1.setBorder(0);
//        PdfPCell cell2 = new PdfPCell(new Paragraph(medicalTechnology.getTechName(), new Font(bfChinese, 10, Font.NORMAL)));
//        cell2.setFixedHeight(30);
//        cell2.setBorder(0);
//        cell2.setPaddingLeft(10);
//        PdfPCell cell3 = new PdfPCell(new Paragraph("项目规格及项目类型", new Font(bfChinese, 14, Font.NORMAL)));
//        cell3.setFixedHeight(25);
//        cell3.setBorder(0);
//        PdfPCell cell4 = new PdfPCell(new Paragraph(medicalTechnology.getTechFormat()+medicalTechnology.getTechType(), new Font(bfChinese, 10, Font.NORMAL)));
//        cell4.setFixedHeight(30);
//        cell4.setBorder(0);
//        cell4.setPaddingLeft(10);
//        PdfPCell cell5 = new PdfPCell(new Paragraph("项目价格及价格类型", new Font(bfChinese, 14, Font.NORMAL)));
//        cell5.setFixedHeight(25);
//        cell5.setBorder(0);
//        PdfPCell cell6 = new PdfPCell(new Paragraph(medicalTechnology.getTechPrice()+medicalTechnology.getPriceType(), new Font(bfChinese, 10, Font.NORMAL)));
//        cell6.setFixedHeight(30);
//        cell6.setBorder(0);
//        cell6.setPaddingLeft(10);
//        tableOrder.addCell(cell1);
//        tableOrder.addCell(cell2);
//        tableOrder.addCell(cell3);
//        tableOrder.addCell(cell4);
//        tableOrder.addCell(cell5);
//        tableOrder.addCell(cell6);
//        document.add(tableOrder);
//
//        //增加logo，绝对定位居于右上角
////        Image image = Image.getInstance("src/main/resources/static/images/dgut.jpeg");
////        image.setAbsolutePosition(440,690);
////        document.add(image);
//
//        //设置pdf底部版权说明
//        PdfContentByte cb = writer.getDirectContent();
//        BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
//        cb.beginText();
//        cb.setFontAndSize(bf, 11);
//        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "该收费单仅供参考", 300, 40, 0);
//        cb.setFontAndSize(bf, 13);
//        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "宇宙声明及解释权仅归医生本人所有", 300, 20, 0);
//        cb.endText();
//        document.close();
//    }
//
//}
